<script>
	// //app.js
	import regeneratorRuntime from "@/utils/runtime";
	import {
		store,
		mutations
	} from '@/store/index.js';
	import common from '@/utils/common.js'
	import {
		request
	} from "@/request/index.js"
	import {
		base64src
	} from "./utils/base64";
	// #ifndef MP-ALIPAY
	let accountInfo = uni.getAccountInfoSync()
	console.log('小程序当前版本', accountInfo.miniProgram.envVersion) //develop开发 trial体验版 release正式版
	// #endif
	let extConfig = uni.getExtConfigSync() ? uni.getExtConfigSync() : {};
	console.log(extConfig, 'extConfig')
	export default {
		isTimeOut: false, // 是否超时
		globalData: {
			// primarySkin: `--primary-color: rgb(255, 92, 109);--primary-rgb-color: 255, 92, 109;`,
			// primarySkinObj: {
			// 	primaryColor: 'rgb(255, 92, 109)',
			// 	primaryRGBColor: '255, 92, 109',
			// },
			primarySkin: `--primary-color: rgb(131, 205, 67);--primary-rgb-color: 131, 205, 67;`,
			primarySkinObj: {
				primaryColor: 'rgb(131, 205, 67)',
				primaryRGBColor: '131, 205, 67',
			},
			logDebug: false,
			isSinglePage: false,
			checkUrls: ['/Shopping/addShopping_v1'], //目前可分享朋友圈页面需要验证非单页版的路由
			XcxData: {
				userInfo: {},
				//用户信息getShopCarGoodsCount
				//是否已经注册
				systemInfo: uni.getSystemInfoSync(),
				openid: '',
				appid: extConfig.appid,
				isvAppId: extConfig.isvAppId,
				tempAppId: extConfig.tempAppId,
				merchant_id: extConfig.merchant_id,
				siteBaseUrl: '',
				domian: '',
				store_id: '', //当前请求参数中的门店id
				begin_store_id: '', //切换门店后的门店id
				isLoadInitial: false, //是否已经获取openID完毕
				shoppingCount: 0,
				domain: '',
				statusBarHeight: "",
				timeArrEsDay: 0,
				plus_register_state: 0, //plus会员引导
				vip_register_state: 0, //vip会员引导
				launch_over: '',
				store_name: '', // 门店名称
				isvEntryVoucher: false, // 是否进入领取代金券公众号
				user_type: 1, // 1 普通 2 plius 3 vip
				share_uid: '', //分享人id
			},

			//获取页面加载时的参数
			getOnLaunchParam(options) {
				if (!options.scene) {
					return {};
				}
				let scene = decodeURIComponent(options.scene);
				let sceneArr = scene.split('&');
				let obj = {};
				sceneArr.forEach((item) => {
					let arr = item.split('=');
					if (arr.length == 2) {
						obj[arr[0]] = arr[1];
					}
				})
				return obj;
			},
			handleLaunchParam(options) {
				// #ifdef MP-WEIXIN
				//微信生成不限量海报链接处理
				let query = {
					...options.query
				};
				if (query.scene) delete query.scene;
				if (options.query.scene && (!query || JSON.stringify(query) == '{}')) {
					console.log('options.query.scene', options.query.scene);
					let obj = this.getOnLaunchParam(options.query);
					if (JSON.stringify(obj) != '{}') {
						options.query = obj;
					}
				}
				//微信聚合码参数处理
				if (options.query.q) {
					let q = decodeURIComponent(options.query.q);
					let arr = q.split('store_id/');
					if (arr[1] && /[0-9]/g.test(arr[1])) {
						options.query.store_id = arr[1]
					}
				}
				// #endif
				/**
				 * &store_id => &s 门店id
				 * &distributor_id => &d 分销员id
				 * &share_uid => &su    分享人uid
				 * &share_guide_id => &sg    导购员id
				 * */
				if (options.query && (options.query.store_id || options.query.s)) {
					store.store_id = options.query.store_id || options.query.s;
					store.begin_store_id = options.query.store_id || options.query.s;
				}
				if (options.query && (options.query.share_uid || options.query.su)) {
					this.XcxData.share_uid = options.query.share_uid || options.query.su;
				}
			},
			resetStoreId() {
				if (store.begin_store_id) {
					store.store_id = store.begin_store_id;
				}
			},
			//用户登录
			userLogin(fn, scopes = 'auth_base') {
				uni.login({
					scopes: scopes,
					success: (res) => {
						if (res.code) {
							var code = res.code;
							this.sendRequest({
								url: '/Register/getOpenId',
								data: {
									code: code,
									share_uid: this.XcxData.share_uid ? this.XcxData.share_uid : '',
								},
								needSign: false,
								showLoading: false,
								success: async (res) => {
									if (res.status == 1) {
										this.XcxData.user_type = res.data.type;
										//用户已注册
										uni.setStorageSync('userInfo', res.data);
										uni.setStorageSync('signKey', res.data.key);
										this.XcxData.userInfo = res.data;
										this.XcxData.openid = res.data.openid;
										// #ifdef MP-ALIPAY
										// 存储支付宝access_token--用户判断是否登录过期
										if (scopes == 'auth_user') {
											uni.setStorageSync('valid_access_token', {
												time: new Date().getTime(),
												value: res.data.access_token
											})
										}
										// #endif
									} else if (res.status == 2) {
										//未注册
										this.XcxData.openid = res.data.openid;
									} else {
										return uni.showToast({
											title: res.msg,
											icon: 'none',
											duration: 1500,
											mask: false
										});
									}

									this.XcxData.plus_register_state = res.plus_register_state; // plus会员注册状态
									this.XcxData.vip_register_state = res.vip_register_state; // vip会员注册状态
									store.showStoreTypeState = res.show_store_type_status == 1 ? true : false;
									store.integral_name = res.integral_name;//获取商户自定义积分名称 res.integral_name
									store.integral_arrive_cash = res.integral_arrive_cash;
									store.marketing_methods = res.marketing_methods;

									store.userInfo = res.data; //存储用户信息

									mutations.skinPeeler(res.data.skin, res.data.status_bar_type)
									store.mallPreviewState = res.plug.mallpreview;
									// 写入是否有装修权限
									store.storediy = res.plug.storediy;
									// 写入是否需要自定义导航栏
									store.navigation_status = res.data.navigation_status ? true : false;
									store.merHomeState = res.applet_home_page_type == 1 ? true : false;
									if (res.applet_home_page_type == 1 && !store.merShoppingGoodsList.length) {
										mutations.getShopList(); //获取商户版购物车数据列表
									}
									typeof fn == "function" && fn();
								},
								fail: (err) => {
									uni.showToast({
										title: '请求发生错误，请稍后重试',
										icon: 'none',
										duration: 1500,
										mask: true
									});
								},
							});
						}
					},
					fail: (res) => {
						typeof fn == "function" && fn();
						// uni.showToast({
						// 	title: '小程序用户登录失败',
						// 	icon: 'none',
						// 	duration: 1500,
						// 	mask: false
						// });
					}
				});
			},
			
			//获取最近门店的ID 
			getNearestStore() {
				return new Promise(async resolve => {
					const location = await mutations.getLocation();

					if (!location) {
						uni.showModal({
							title: '温馨提示',
							content: '未获取到您的位置，您无法下单',
							showCancel: false,
							success: (res) => {
								if (res.confirm) {
									uni.navigateBack({
										delta: 1
									})
								}
							}
						})

						return resolve(false)
					}
					const {
						status,
						data,
						message
					} = await request('SmallProgramApi/Store/getRecentlyStoreInfo', {
						longitude: location.longitude,
						latitude: location.latitude,
					}, false);
					if (status != 1) {
						uni.showToast({
							title: message,
							icon: "none"
						})
						return resolve(false)
					}
					store.store_id = data.store_id
					resolve(true);
				})
			},

			//获取门店列表
			getStoreList(get_all = false, store_id = '') {
				return new Promise(async (resolve, reject) => {
					const position = await mutations.getLocation();
					const response = await request('SmallProgramApi/Store/getStore_v1', {
						lng: position ? position.longitude : '',
						lat: position ? position.latitude : '',
						get_all: get_all ? 1 : 0,
						store_id: store_id,
					})
					if (response.status == 1) {
						resolve(response);
					} else {
						if (position || response.auth_location_status != 1) return uni.showToast({
							title: response.message,
							icon: 'none'
						}) && reject();
						uni.showModal({
							title: '提示',
							content: '您拒绝了获取地理位置，无法正常获取附近门店，是否开启？',
							confirmText: '去开启',
							success: (res) => {
								if (!res.confirm) return reject();
								uni.openSetting({
									success(res) {}
								});
								uni.showModal({
									title: '提示',
									content: '如已已开启定位功能，点击重试',
									showCancel: true,
									confirmText: '重试',
									success: (res) => {
										if (res.confirm) {
											return this.getStoreList(get_all, store_id);
										} else {
											reject()
										}
									}
								})
							}
						});
					}
				})
			},
			//获取登录状态
			loginState() {
				return this.XcxData.userInfo && this.XcxData.userInfo.login_state == 1;
			},
			/**
			 * 公共发起请求方法
			 */
			sendRequest(param, customSiteUrl) {
				let showLoading = param.showLoading === false ? false : true;

				showLoading && uni.$emit('showLoading', param.loadTitle ? param.loadTitle : '加载中...')

				let data = common.joinRequestParam(param);

				let requestUrl; //请求地址
				// 自定义路径
				if (customSiteUrl) {
					requestUrl = customSiteUrl + param.url;
				} else {
					if (param.url.substr(0, 1) !== '/') {
						param.url = '/' + param.url;
					}
					requestUrl = `${this.XcxData.siteBaseUrl}${param.url}`;
				}
				this.logDebug && console.log('request:', requestUrl, param)
				uni.request({
					url: requestUrl,
					data: data,
					method: 'post',
					header: {
						"content-type": "application/x-www-form-urlencoded"
					},
					success: (res) => {
						this.logDebug && console.log('response:', requestUrl, res.data)
						this.isTimeOut = false;

						showLoading && uni.$emit('hideLoading');

						if (res.data.status == -1 && param.needLogin !== false) {
							uni.hideLoading();
							uni.showModal({
								title: '登陆提示',
								content: '您还未登录，暂不能体验该功能，请先登录！',
								showCancel: true,
								cancelText: '暂不登录',
								cancelColor: '#999',
								confirmText: '去登录',
								confirmColor: '#ff5c6d',
								success: (res) => {
									if (res.confirm) {
										uni.navigateTo({
											url: '/pages/my/my'
										});
									}
								}
							});
						} else if (res.data.status == -2 || res.data.status == -3) {
							uni.removeStorageSync('userInfo');
							uni.removeStorageSync('signKey');
							this.XcxData.userInfo = {};
							this.userLogin(() => {
								this.sendRequest(param);
							});
						} else {
							res.data.message = res.data.message ? res.data.message : res.data.msg;
							typeof param.success == 'function' && param.success(res.data);
						}
					},
					fail: (res) => {
						if (showLoading) {
							uni.hideLoading();
						}

						if (res.errMsg == "request:fail timeout" && !this.isTimeOut) {
							uni.showToast({
								title: '网络超时，请检查您的网络',
								icon: 'none',
								duration: 1500,
								mask: true
							});
							this.isTimeOut = true;
						}

						typeof param.fail == 'function' && param.fail(res.data);
					},
					complete: (res) => {
						typeof param.complete == 'function' && param.complete(res.data);
					}
				});
			},
			//添加到门店购物车
			addToCar(data) {
				return new Promise((resolve, reject) => {
					data.fixed_num = data.fixed_num ? data.fixed_num : 0; //是否不可修改数量
					data.type = data.type ? data.type : 1;
					this.sendRequest({
						url: '/Shopping/addShopping_v1',
						data: data,
						loadingTitle: '正在添加...',
						success: (res) => {
							if (res.status == 1) {
								uni.showToast({
									title: '已加入购物车',
									icon: 'success',
									duration: 1000,
									mask: false
								});
								resolve(true)
							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none',
									duration: 1500,
									mask: true
								});
								resolve(false)
							}
						}
					});
				})
			},
			//全局获取购物车商品数量
			getShopCarGoodsCount() {
				this.sendRequest({
					url: '/Shopping/getShopCarGoodsCount',
					showLoading: false,
					needLogin: false,
					success: async (res) => {
						var count = 0;

						if (res.status == 1) {
							count = res.count;
						}
						this.XcxData.shoppingCount = await this.setShoppingCount(count); //用获得的数字进行设置
					},
					fail: () => {
						uni.removeTabBarBadge({
							index: 2
						});
					}
				});
			},

			//设置购物车数量
			setShoppingCount(count = 0) {
				return new Promise((resolve) => {
					if (count > 999) {
						count = '999+';
					}

					if (count == 0) {
						uni.removeTabBarBadge({
							index: 2
						});
					} else {
						uni.setTabBarBadge({
							index: 2,
							text: String(count)
						});
					}
					resolve(count)
				})
			},

			/**新增访问商品记录
			 * @param {Object} param
			 * {
			 * goods_id			商品id
			 * browse_duration	浏览时长	
			 * }
			 */
			async addVisitGoodsRecord(param) {
				request('SmallProgramApi/My/addUserVisitGoodsRecord', param, false);
			},
			// 修改post参数
			modifyPostParam(obj) {
				let query = '',
					name,
					value,
					fullSubName,
					subName,
					subValue,
					innerObj,
					i;

				for (name in obj) {
					value = obj[name];

					if (value instanceof Array) {
						for (i = 0; i < value.length; ++i) {
							subValue = value[i];
							fullSubName = name + '[' + i + ']';
							innerObj = {};
							innerObj[fullSubName] = subValue;
							query += this.modifyPostParam(innerObj) + '&';
						}
					} else if (value instanceof Object) {
						for (subName in value) {
							subValue = value[subName];
							fullSubName = name + '[' + subName + ']';
							innerObj = {};
							innerObj[fullSubName] = subValue;
							query += this.modifyPostParam(innerObj) + '&';
						}
					} else if (value !== undefined && value !== null && value !== '') query += encodeURIComponent(
							name) + '=' +
						encodeURIComponent(value) + '&';
				}

				return query.length ? query.substr(0, query.length - 1) : query;
			},

			showToast(param) {
				uni.showToast({
					title: param.title,
					icon: param.icon,
					duration: param.duration || 1500,
					success: (res) => {
						typeof param.success == 'function' && param.success(res);
					},
					fail: (res) => {
						typeof param.fail == 'function' && param.fail(res);
					},
					complete: (res) => {
						typeof param.complete == 'function' && param.complete(res);
					}
				});
			},
			hideToast() {
				uni.hideToast();
			},
			showModal(param) {
				uni.showModal({
					title: param.title || '提示',
					content: param.content,
					showCancel: param.showCancel || false,
					cancelText: param.cancelText || '取消',
					cancelColor: param.cancelColor || '#000000',
					confirmText: param.confirmText || '确定',
					confirmColor: param.confirmColor || '#3CC51F',
					success: (res) => {
						if (res.confirm) {
							typeof param.confirm == 'function' && param.confirm(res);
						} else {
							typeof param.cancel == 'function' && param.cancel(res);
						}
					},
					fail: (res) => {
						typeof param.fail == 'function' && param.fail(res);
					},
					complete: (res) => {
						typeof param.complete == 'function' && param.complete(res);
					}
				});
			},

			/**
			 * 判断时间范围（仅针对时和分）
			 */
			checkTime(range_time, choose_time) {
				var thisYears = new Date().getFullYear();
				var thisMonth = new Date().getMonth();
				var thisDate = new Date().getDate();
				var range_arr = range_time.split('-');
				var start = thisYears + '/' + (thisMonth + 1) + '/' + thisDate + ' ' + range_arr[0] + ':00';
				start = Date.parse(new Date(start));
				var end = thisYears + '/' + (thisMonth + 1) + '/' + thisDate + ' ' + range_arr[1] + ':00';
				end = Date.parse(new Date(end));
				var thisHours = new Date().getHours();
				var thisMinutes = new Date().getMinutes();
				var thisTime = thisYears + '/' + (thisMonth + 1) + '/' + thisDate + ' ' + thisHours + ':' +
					thisMinutes + ':00';
				thisTime = Date.parse(new Date(thisTime));

				if (thisTime < start || thisTime > end) {
					return false;
				} else {
					return true;
				}
			},

			showToast(obj) {
				if (!obj || !obj.title) {
					return;
				}

				var icon = obj.icon ? obj.icon : 'success';

				if (obj.duration) {
					var duration = obj.duration;
				} else {
					var duration = obj.title.length * 300;
				}

				uni.showToast({
					title: obj.title,
					icon: icon,
					image: obj.image ? obj.image : '',
					duration: duration,
					mask: obj.mask ? obj.mask : false
				});

				if (obj.success && typeof obj.success == "function") {
					setTimeout(() => {
						obj.success();
					}, duration);
				}
			},

			//点击保存到相册
			saveImg(param) {
				uni.saveImageToPhotosAlbum({
					filePath: param.url,
					success(res) {
						uni.showToast({
							title: '保存成功',
							success: (res) => {
								setTimeout(() => {
									typeof param.success == "function" && param.success();
								}, 800)
							}
						})
					},
					fail: (res) => {
						console.log('saveImg:fail', res)
						if (res.errMsg == 'saveImageToPhotosAlbum:fail auth deny') {
							uni.showModal({
								content: '请打开添加到相册权限后再重试',
								showCancel: false,
								confirmText: '去打开',
								confirmColor: '#333',
								success: (res) => {
									if (res.confirm) {
										uni.openSetting()
									}
								},
							});
						}
					}
				});
			},

			/**
			 * 清除生成海报的临时文件
			 */
			clearDir() {
				const fsm = uni.getFileSystemManager(); //获取全局唯一的文件管理器
				const __dirPath = `${uni.env.USER_DATA_PATH}`; //路径

				fsm.readdir({
					//读取目录内文件列表
					dirPath: __dirPath,
					success: res => {
						const {
							errMsg,
							files
						} = res;

						if (errMsg == 'readdir:ok') {
							files.forEach(item => {
								fsm.unlink({
									filePath: __dirPath + '/' + item
								});
							});
						}
					}
				});
			},

			/**
			 * 配送、自提时间选择生成 月-日 数组
			 * @param times 固定的时间段数组[[[10,00],[12,00]],[[12,30],[14,50]],[[17,00],[20,30]]]
			 * @param es_time 需要往后延长的开始时间的长度(秒为单位)
			 * @param end_day 结束的天数 默认7天月日
			 * @return Array 返回一个 月-日 的数组
			 */
			createMonthDay(times, es_time = 0, end_day = 0) {
				let timeData = this.getThisTime(times);
				let monthDay = []; //月日列表
				let thisTime = timeData.thisTime; //当前时间的时间戳精确到秒
				//临时计算往后延长到的时间的时间戳
				let temp_time = this.roundPrice(thisTime + es_time * 1000 - timeData.startTime);
				let day = parseInt(this.roundPrice(temp_time / 86400000)); //计算需要往后延长的天

				this.timeArrEsDay = day; //存储实际延时的天数
				let this_day_more = temp_time % 86400; //减掉天之后剩余的时间戳
				if (day < 1) {
					if (thisTime + es_time * 1000 > timeData.endTime) {
						monthDay = ['明天'];
						thisTime = thisTime + 172800000;
						day = 1;
					} else {
						monthDay = ['今天', '明天'];
						thisTime = thisTime + 172800000;
						day = 2;
					}
				} else if (day == 1 && thisTime + es_time * 1000 < timeData.endTime) {
					monthDay = ['明天'];
					thisTime = thisTime + 172800000;
				} else {
					thisTime += es_time * 1000;
					//计算是延迟后最晚的时间是多少秒
					let endTime = parseInt(this.roundPrice(timeData.startTime + day * 86400000 + times[times.length - 1][1]
						[0] *
						3600000 + times[times.length - 1][1][1] * 60000));
					if (thisTime > endTime) {
						//不足够再加一天
						thisTime += 86400000;
						day += 1;
					}
					//把明天转为文字的明天
					if (thisTime - timeData.startTime < 86400000 * 2) {
						monthDay = ['明天'];
						thisTime += 86400000;
					}
					this.timeArrEsDay = day; //存储实际延时的天数
				}
				if (end_day == 0) end_day = this.roundPrice(day + 7 - monthDay.length);
				for (let i = day; i <= end_day; i++) {
					let md = this.getDate('m-d', thisTime);
					thisTime += 86400000;
					monthDay.push(md);
				}
				return monthDay;
			},

			/**
			 * 配送、自提时间选择生成 时 数组
			 * @param times 固定的时间段数组[[[10,00],[12,00]],[[12,30],[14,50]],[[17,00],[20,30]]]
			 * @param cd 已生成的 月日,时,分 的数组
			 * @param ci 已选的 月日,时,分 下标的数组
			 * @param es_time 需要往后延长的开始时间的长度(秒为单位)
			 * @return Array 返回一个 时 的数组
			 */
			createHours(times, cd, ci, es_time = 0) {
				let hours = [];
				let timeData = this.getThisTime(times);
				let thisTime = timeData.thisTime; //当前时间的时间戳精确到秒
				//临时计算往后延长到的时间的时间戳
				let temp_time = this.roundPrice(thisTime + es_time * 1000 - timeData.startTime);
				let day = parseInt(this.roundPrice(temp_time / 86400000)); //计算需要往后延长的天
				//针对不足加一的情况
				if (day == 0 && ci[0] == 0 && cd[0][0] == '明天') {
					temp_time = 0;
				} else if (day < this.timeArrEsDay) {
					temp_time = 0;
				}
				let h = parseInt((temp_time % 86400000) / 3600000); //计算需要往后延长的时
				let m = parseInt((temp_time % 3600000) / 60000); //计算需要往后延长的分

				times.forEach((item) => {
					let i = item[0][0] * 1;
					let len = item[1][0] * 1;
					//时小于10前面补0
					//时的数组跑循环，从今天的起始时到结束时
					for (i; i <= len; i++) {
						// console.log('进入循环')
						let hh = i >= 10 ? i : ('0' + i);
						if (ci[0] != 0) {
							// console.log(i+': 选择的日不是第一项，插入时');
							//选择的日不是第一项，插入时
							(hours.indexOf(hh) == -1) && hours.push(hh);
						} else {
							//选择的日是第一项
							//判断循环到的时是否大于延时的时并且循环到的时
							if (i > h) {
								// console.log(i+': 循环到的时大于延时的时，插入时');
								//循环到的时大于延时的时，插入时
								(hours.indexOf(hh) == -1) && hours.push(hh);
							} else if (i == h && i != len) {
								// console.log(i+': 循环到的时等于延时的时并且不是可选时间的最后一个时，插入时');
								//循环到的时等于延时的时并且不是可选时间的最后一个时，插入时
								(hours.indexOf(hh) == -1) && hours.push(hh);
							} else if (i == h && i == len && m < item[1][1] * 1) {
								// console.log(i+': 循环到的时等于延时的时并且是可选时间的最后一个时并且延时的分是否小于可选分，插入时');
								//循环到的时等于延时的时并且是可选时间的最后一个时并且延时的分是否小于可选分，插入时
								(hours.indexOf(hh) == -1) && hours.push(hh);
							}
						}
					}
				});
				return hours;
			},

			/**
			 * 配送、自提时间选择生成 分 数组
			 * @param times 固定的时间段数组[[[10,00],[12,00]],[[12,30],[14,50]],[[17,00],[20,30]]]
			 * @param cd 已生成的 月日,时,分 的数组
			 * @param ci 已选的 月日,时,分 下标的数组
			 * @param es_time 需要往后延长的开始时间的长度(秒为单位)
			 * @return Array 返回一个 分 的数组 基本间隔为5分钟
			 */
			createMinutes(times, cd, ci, es_time = 0) {
				let minutes = [];
				let timeData = this.getThisTime(times);
				let thisTime = timeData.thisTime; //当前时间的时间戳精确到秒
				//临时计算往后延长到的时间的时间戳
				let temp_time = this.roundPrice(thisTime + es_time * 1000 - timeData.startTime);
				let h = parseInt((temp_time % 86400000) / 3600000); //计算需要往后延长的时
				let m = parseInt((temp_time % 3600000) / 60000); //计算需要往后延长的分
				times.forEach((item) => {
					if (cd[1][ci[1]] * 1 >= item[0][0] * 1 && cd[1][ci[1]] * 1 <= item[1][0] * 1) {
						let start = 0;
						let end = 59;
						if (cd[1][ci[1]] * 1 == item[0][0] * 1) {
							//选择的时等于开始时 start定为开始的秒
							start = item[0][1];
						}
						if (cd[1][ci[1]] * 1 == item[1][0] * 1) {
							//选择的时等于结束时 end定为结束的秒
							end = item[1][1];
						}
						// console.log(start,end,m)
						if (ci[0] == 0 && ci[1] == 0 && cd[1][0] * 1 == h && es_time > 0 && m >= start) {
							//选择第一项月日和第一项时 且第一项的时等于当前时间 start定为延时的秒
							// console.log(123456);
							start = m;
						} else if (ci[0] == 0 && ci[1] == 0 && h >= item[0][0] * 1 && cd[0][0] == '今天' && m >
							start) {
							//选择第一项是今天 并且时是当前时，判断分的其起始值
							// console.log(456789);
							start = m;
						}
						// console.log(start,end,m,h,timeData.thisHours)
						//如果开始时间小于等于结束时间则写入秒的数组
						if (start <= end) {
							start = start * 1; //转为数字
							end = end * 1; //转为数字
							let multiple = (start * 1) % 5; //获取余数
							if (multiple > 0) {
								minutes.push(start >= 10 ? start : ('0' + start));
								start = this.roundPrice(start + (5 - multiple));
							}
							if (start >= 60) return false;
							for (let i = start; i <= end; i += 5) {
								minutes.push(i >= 10 ? i : ('0' + i));
							}
						}
						return false;
					}
				});
				return minutes;
			},

			/**
			 * 获取当前时间等信息
			 * @param times 固定的时间段数组[[[10,00],[12,00]],[[12,30],[14,50]],[[17,00],[20,30]]]
			 */
			getThisTime(times) {
				let date = new Date();
				let thisYears = date.getFullYear(); //当前年
				let thisMonth = date.getMonth() + 1; //当前月
				let thisDate = date.getDate(); //当前日
				let thisHours = date.getHours(); //当前时
				let thisMinutes = date.getMinutes(); //当前分
				let len = times.length - 1;
				let start_time = thisYears + '/' + thisMonth + '/' + thisDate + ' 00:00:00'; //当天的开始时间
				let end_time = thisYears + '/' + thisMonth + '/' + thisDate + ' ' + times[len][1][0] + ':' + times[len][1][
						1
					] +
					':00'; //当天的结束时间
				return {
					thisYears: thisYears, //当前年
					thisMonth: thisMonth, //当前月
					thisDate: thisDate, //当前日
					thisHours: thisHours, //当前时
					thisMinutes: thisMinutes, //当前分
					thisTime: Date.parse(new Date()), //当前时间戳
					startTime: Date.parse(new Date(start_time)), //今日开始时间戳
					endTime: Date.parse(new Date(end_time)) //今日结束时间戳
				};
			},

			/**
			 * 根据时间戳（单位，毫秒），获取年月日，时分秒
			 */
			getDate(separator, time) {
				if (separator && separator.length > 11) {
					return '';
				}

				separator = separator ? separator : "y-m-d h:i:s";
				separator = separator.toLowerCase();
				var end_date = '';
				var date = time ? new Date(time) : new Date();
				var str = 'ymdhis';

				for (var i = 0; i < separator.length; i++) {
					switch (separator.charAt(i)) {
						case 'y':
							end_date += date.getFullYear();
							break;

						case 'm':
							let month = date.getMonth() + 1;

							if (month >= 1 && month <= 9) {
								month = "0" + month;
							}

							end_date += month;
							break;

						case 'd':
							let strDate = date.getDate();

							if (strDate >= 1 && strDate <= 9) {
								strDate = "0" + strDate;
							}

							end_date += strDate;
							break;

						case 'h':
							let hours = date.getHours();

							if (hours >= 0 && hours <= 9) {
								hours = "0" + hours;
							}

							end_date += hours;
							break;

						case 'i':
							let minutes = date.getMinutes();

							if (minutes >= 0 && minutes <= 9) {
								minutes = "0" + minutes;
							}

							end_date += minutes;
							break;

						case 's':
							let seconds = date.getSeconds();

							if (seconds >= 0 && seconds <= 9) {
								seconds = "0" + seconds;
							}

							end_date += seconds;
							break;

						default:
							end_date += separator.charAt(i);
					}
				}

				return end_date;
			},

			/**
			 * 根据时间戳（单位，毫秒），获取 天、时、分、秒
			 */
			getDayHis(time) {
				let arr = [];

				arr[0] = Math.floor(time / 1000 / 60 / 60 / 24); //天

				arr[1] = Math.floor(time / 1000 / 60 / 60 % 24); //时

				arr[2] = Math.floor(time / 1000 / 60 % 60); //分

				arr[3] = Math.floor(time / 1000 % 60); //秒

				arr[1] = arr[1] > 9 ? arr[1] : '0' + arr[1];
				arr[2] = arr[2] > 9 ? arr[2] : '0' + arr[2];
				arr[3] = arr[3] > 9 ? arr[3] : '0' + arr[3];
				return arr;
			},

			//计算价格
			roundPrice(num) {
				let numStr = num.toString();
				let numLast = numStr.split(".");

				if (numLast[1] && (numLast[1].length > 3 && numLast[1].slice(2, 6) == "4999" || numLast[1].length >= 3 && numLast[1].slice(2, 3) == "5")) {
					num = parseFloat(numLast[0]) + (parseFloat(numLast[1].slice(0, 2)) + 1) / 100;
				}

				num = Math.round(num * 100) / 100;
				return num;
			},

			//处理营业时间、发货时间为二维数组
			handleTimeArr(times) {
				let arr = [];
				times.forEach((item) => {
					arr.push([item[0].split(':'), item[1].split(':')]);
				});
				return arr;
			},
			//验证是否登陆
			verifyLogin(adr, callback) {
				if (this.XcxData.userInfo.login_state != 1) {
					uni.showModal({
						title: '登陆提示',
						content: '您还未登录，暂不能体验该功能，请先登录！',
						showCancel: true,
						cancelText: '暂不登录',
						cancelColor: '#999',
						confirmText: '去登录',
						confirmColor: '#ff5c6d',
						success: (res) => {
							if (res.confirm) {
								this.toMyLogin(adr)
							}
						}
					});
				} else {
					callback()
				}
			},

			toMyLogin(adr) {
				uni.setStorageSync('loginCallbackAdr', adr);
				uni.navigateTo({
					url: "/pages/my/my"
				})
			},
			loginCallback() {
				let adr = uni.getStorageSync('loginCallbackAdr');
				uni.removeStorageSync('loginCallbackAdr');
				uni.navigateBack({
					delta: 1
				})
			},
			// 展示plus会员价条件
			showPlusPrice(item) {
				let show = false
				// #ifdef H5
				return show
				// #endif
				// #ifndef H5
				// 是否开启会员价
				if (item.plus_mem_status == 1 && item.plus_price) {
					// 判断用户是否为plus会员或是否开启plus会员引导
					if (this.XcxData.user_type == 2 || this.XcxData.plus_register_state == 1) {
						show = true
					}
				} else {
					show = false
				}
				// #endif
				return show
			},

			// 展示会员价条件
			showVipPrice(item) {
				let show = false
				// #ifdef H5
				return show
				// #endif
				// #ifndef H5
				// 是否开启会员价
				if (item.shop_mem_status == 1 && item.shop_mem_price) {
					// 判断是否为会员或会员引导价格
					if (this.XcxData.user_type == 3 || this.XcxData.vip_register_state == 1) {
						show = true
					}
					// 对于普通用户并且开启了plus会员价引导
					if (this.XcxData.user_type == 1 && this.XcxData.plus_register_state == 1 && item.plus_mem_status == 1) {
						show = false
					}
					// 对于plus会员
					if (this.XcxData.user_type == 2 && item.plus_mem_status == 1) {
						show = false
					}

				} else {
					show = false
				}
				return show
				// #endif
			},

			showOnlinePrice(item) {
				let show = false
				if (item.online_price && (this.XcxData.user_type == 1 || (this.XcxData.user_type == 2 && item.plus_mem_status == 2) ||
						(this.XcxData.user_type == 3 && item.shop_mem_status == 2))) {
					show = true
				} else {
					show = false
				}
				return show
			},
		},
		onLaunch(options) {
			console.log('App onLaunch options:', options)

			this.globalData.handleLaunchParam(options);
			this.globalData.getNearestStore()

			// 监听自定义全局页面loading的显示与隐藏方法
			uni.$on("showLoading", (data) => {
				mutations.showLoading(data)
			});
			uni.$on("hideLoading", () => {
				mutations.hideLoading()	
			});

			let systemInfo = uni.getSystemInfoSync();
     
			store.osName = systemInfo.osName;
			console.log('store.osName', store.osName)
			// console.log('systemInfo', systemInfo)
			if (systemInfo.safeArea && systemInfo.screenHeight - systemInfo.safeArea.bottom > 0) {
				store.bottomHeight = 32; //写固定的，以后遇到其他的再说，不然在支付宝开发者工具展示有问题
				// store.bottomHeight = (parseInt((systemInfo.screenHeight - systemInfo.safeArea.bottom) * 0.5 / (uni.upx2px(100) / 100)));
			}
			// console.log('store.bottomHeight', store.bottomHeight)

			//处理域名
			if (extConfig.siteBaseUrl.indexOf('://') != -1) {
				this.globalData.XcxData.siteBaseUrl = extConfig.siteBaseUrl;
				this.globalData.XcxData.domain = extConfig.domain;
			} else {
				this.globalData.XcxData.domain = 'https://' + extConfig.domain;
				this.globalData.XcxData.siteBaseUrl = 'https://' + extConfig.siteBaseUrl;
			}
			store.domain = this.globalData.XcxData.domain;
			store.image_header = this.globalData.XcxData.domain.replace('/index.php', '') + '/Public/miniProgram/images/';
			store.statusBarHeight = systemInfo.statusBarHeight;

			this.globalData.logDebug = uni.getStorageSync('logDebug') === true ? true : false;
			this.globalData.isSinglePage = options.mode == 'singlePage';
			//获取用户信息
			this.globalData.userLogin(() => {
				this.$isResolve();
			});

			try {
				const updateManager = uni.getUpdateManager();
				updateManager.onCheckForUpdate((res) => {
					// 请求完新版本信息的回调
					console.log(res.hasUpdate);
				});
				updateManager.onUpdateReady(() => {
					uni.showModal({
						title: '更新提示',
						content: '新版本已经准备好，是否重启应用？',
						success: (res) => {
							if (res.confirm) {
								// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
								updateManager.applyUpdate();
							}
						}
					});
				});
				updateManager.onUpdateFailed(() => { // 新版本下载失败
				}); //获取用户openid
			} catch (e) {
				//TODO handle the exception
			}


		},
		onShow(options) {
			// console.log('App onShow options:', options)
			this.globalData.handleLaunchParam(options);
			
			// #ifdef MP-WEIXIN
			uni.showShareMenu({
				withShareTicket: true
			});
			// #endif
		},
	};
</script>
<style lang="scss">
	@import "./app.css";
	@import './static/iconfont/iconfont.css';
	@import './static/font/qh-rt-single.css';
	@import './static/icon/iconfont.css';
	@import "./components/choose-sku/choose-sku.css";
	/* #ifdef MP-ALIPAY */
	@import './static/font/qh-rt-al-single.css';
	/* #endif */
</style>
